package com.lagou.xsq_springboot_rpc_provider.scanner;

import com.lagou.xsq_springboot_rpc_provider.annotation.XsqService;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AnnotationTypeFilter;

import java.util.Set;

/**
 * @ClassName RPCXsqServiceClassPathSacnner
 * @Description TODO
 * @Author xsq
 * @Date 2020/5/30 10:53
 **/
public class RPCProviderXsqServiceClassPathSacnner extends ClassPathBeanDefinitionScanner {

    public RPCProviderXsqServiceClassPathSacnner(BeanDefinitionRegistry registry) {
        super(registry);
    }

    public RPCProviderXsqServiceClassPathSacnner(BeanDefinitionRegistry registry, boolean useDefaultFilters) {
        super(registry, useDefaultFilters);
    }

    public RPCProviderXsqServiceClassPathSacnner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment) {
        super(registry, useDefaultFilters, environment);
    }

    public RPCProviderXsqServiceClassPathSacnner(BeanDefinitionRegistry registry, boolean useDefaultFilters, Environment environment, ResourceLoader resourceLoader) {
        super(registry, useDefaultFilters, environment, resourceLoader);
    }

    /**
     * 核心代码,使知道需要register哪个注解修饰的bean
     */
    public void registerFilters() {
        addIncludeFilter(new AnnotationTypeFilter(XsqService.class));
    }

    @Override
    protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
        return super.doScan(basePackages);
    }
}
